import React,{Component} from 'react'
import {CheckTaskStyle} from './StyleCheckTask'
import { Toast , Modal } from 'antd-mobile'
import {
    Route,
    withRouter,
  } from 'react-router-dom'
  import qs from "qs"
import Navigation from 'components/Navigation/Navigation'
import Message from './Message'
import UIButton from 'components/UIButton/UIButton'
import connect from 'pages/redux-component/connect'

import ht from 'images/my/huitui@3x.png'

class CheckTask extends Component{
    state = {
        taskData:{}
      }
    render(){
        return(
            <CheckTaskStyle {...this.props}>
                <Navigation 
                    leftImg = {ht} 
                    leftImgWidth = '.2rem'
                    leftImgHeight = '.2rem'
                    leftPadding = '0 0 0 .15rem'
                    title = "接单任务信息"
                    titleSize = '.17rem'
                    clickLeft = {()=>this.onClickLeft("left")}
                ></Navigation>
                <div className="container">
                    <div className="message">
                        <Message title="" message={this.state.taskData.tname}></Message>
                        <Message title="" message={this.state.taskData.tcontent}></Message>
                    </div>
                    <div className="secrecy">
                        <p>保密信息</p>
                        <Message title="" message={this.state.taskData.tcontent}></Message>
                        {/* <Message title="联系人" message={this.state.taskData.linkman}></Message>
                        <Message title="手机号" message={this.state.taskData.linkphone}></Message> */}
                    </div>
                    <div className="arrive">
                        <Message title="送达地址：" message={this.state.taskData.staplace}></Message>
                        <Message title="送达时间：" message={this.state.taskData.endtime}></Message>
                    </div>
                    <div className="reward">
                        <p>赏金</p>
                        <div className="money">
                            <p className="yuan">￥</p>
                            <p className="num">{this.state.taskData.price?this.state.taskData.price:'0'}</p>
                        </div>
                    </div>
                    <p className="tishi">温馨提示：请抓紧时间确保商品按时送达</p>
                    <p className="wancheng">完成任务后赏金将在一小时内到账</p>
                    <UIButton
                        title='已完成'
                        width='1.4rem'
                        height='.4rem'
                        borderRadius='.26rem'
                        backgroundColor = "#FFB538"
                        titleColor='#fff'
                        titleSize = '.15rem'
                        margin='0 0 .6rem 26%'
                        clickButton = {()=>this.onClickbtn()}
                    ></UIButton>
                </div>
            </CheckTaskStyle>
        )
    }
    componentDidMount(){
        let tag = this.props.match.params.id
        let body = {tid: tag}
        fetch('/Legang/task/findtid',{   
          method:"POST",
          headers:{
              "Content-type":"application/x-www-form-urlencoded",
          },     
          body: qs.stringify(body)
        })    
        .then(response => response.json())
        .then(result => {
          if(result.flag){
            console.log(result)
            var timestamp = result.data.endtime;
            var d = new Date(timestamp );   
            var date = (d.getFullYear()) + "-" + 
                    (d.getMonth() + 1) + "-" +
                    (d.getDate()) + " " + 
                    (d.getHours()) + ":" + 
                    (d.getMinutes()) + ":" + 
                    (d.getSeconds());
                result.data.endtime = date
            if(result.data.userone){
            if(result.data.userone.exp){
              if(result.data.userone.exp>=500){
                result.data.userone.jd = '100%'
                result.data.userone.dj = 'lv5'
              }else if(result.data.userone.exp>=400){
              result.data.userone.jd = '800%'
              result.data.userone.dj = 'lv4'
              }else if(result.data.userone.exp>=300){
              result.data.userone.jd = '60%'
              result.data.userone.dj = 'lv3'
              }else if(result.data.userone.exp>=200){
              result.data.userone.jd = '40%'
              result.data.userone.dj = 'lv2'
              }else{
                result.data.userone.dj = 'lv1'  
                result.data.userone.jd = '20%'
              }
            }else{
              result.data.userone.dj = 'lv1'
              result.data.userone.jd = '20%'
            }
          }
            this.setState({
              taskData : result.data
            },
            ()=>{
              console.log(this.state.taskData)
              }
            )
          }else{
            Toast.info(result.errorMsg)
          }
          
        })
      }
    onClickLeft(){
        this.props.history.go(-1)
    }
    onClickbtn(){
  
      let ts = {tid:this.state.taskData.tid,uid:this.state.taskData.usertwo.uid}
      console.log(ts)
      let result = fetch('/Legang/task/wcTask',{
        method:"POST",
        headers:{
            "Content-type":"application/x-www-form-urlencoded"
        },
        body: qs.stringify(ts)
        // "email=1486960462@qq.com&password=123456",
        })
        
        .then(response => response.json())
        .then(result => {
            console.log(result)
        })
        this.props.history.go(-1)
    }
}

export default withRouter(connect(CheckTask))